package com.minedata.authorization.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.minedata.authorization.bean.UserBean;

public interface UserMapper {
	
	@Select("select * from t_user where id=#{id}")
	public UserBean findById(Integer id);

	@Select("select * from t_user where username=#{username}")
	public UserBean findByUsername(String username);
	
	@Insert("insert into t_user "
			+ "(username, password, type, name, mail, contact, certType, info, createTime, verify, verifyTime, locked) "
			+ "values "
			+ "(#{userBean.username}, #{userBean.password}, #{userBean.type}, "
			+ "#{userBean.name}, #{userBean.mail}, #{userBean.contact}, "
			+ "#{userBean.certType}, #{userBean.info}, #{userBean.createTime}, "
			+ "#{userBean.verify}, #{userBean.verifyTime}, #{userBean.locked})")
	@Options(useGeneratedKeys = true, keyProperty = "userBean.id")
	public UserBean insertUser(@Param("userBean") UserBean userBean);
	
	@Update("update t_user set password=#{password} where username=#{username}")
	public UserBean updateUserPassword(@Param("userBean") UserBean userBean);
}
